package com.chencs.app.category.service;

import com.chencs.app.AppCommon;
import com.chencs.app.category.mapper.AppCategoryMapper;
import com.chencs.vo.biz.category.CategoryModel;
import com.chencs.vo.biz.product.KeyModel;
import com.chencs.vo.net.request.CategoryRequest;
import com.chencs.vo.net.request.RequestBase;
import com.chencs.vo.net.response.CategoryResponse;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by fangzehua on 2017/7/11.
 */
@Service
@Transactional
public class AppCategoryService {

    @Autowired
    private AppCategoryMapper appCategoryMapper;


    public List<CategoryModel> getCategoryList(CategoryRequest request){
        Map<String,Object> map = new HashMap<>();
       if(StringUtils.isNotBlank(request.getDef())){
           map.put("def",request.getDef());
       }
        List<CategoryModel> list = appCategoryMapper.getCategoryList(map);
        return  list;
    }

    public List<CategoryModel> getAllCategoryList(CategoryRequest request){
        Map<String,Object> map = new HashMap<>();
        if(StringUtils.isNotBlank(request.getDef())){
            map.put("def",request.getDef());
        }
        map.put("cid","1000");
        List<CategoryModel> list = appCategoryMapper.getCategoryList(map);
//        for(CategoryModel model:list){
//            model.setItemModelList(appCategoryMapper.findCategoryItemByCid(model.getCid()));
//        }
        return  list;
    }

    public List<CategoryModel> getOtherCategoryList(CategoryRequest request){
        Map<String,Object> map = new HashMap<>();

        String other = "";
        for(int i=0;i<request.getCategorys().size();i++){
            other = other+request.getCategorys().get(i).getCid()+",";
        }
        if(StringUtils.isNotBlank(other)){
            map.put("other",other.substring(0,other.length() - 1));
         //   System.out.println(other);
        }
        List<CategoryModel> list = appCategoryMapper.getOtherCategoryList(map);
        return  list;
    }


    public  List<KeyModel> getKeyList(RequestBase requestBase){

     return  appCategoryMapper.getKeyList();
    }


}
